<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
  <link rel="stylesheet" title="Default" href="http://acm.math.spbu.ru/~sk1/colorer/my.css">

  <script src="http://acm.math.spbu.ru/~sk1/colorer/highlight.js"></script>
  <script src="http://acm.math.spbu.ru/~sk1/colorer/cpp.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
</head>

<body>

<pre><code>
/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 * Date: 2013.03.19
 */

#include &lt;cstdio&gt;
#include &lt;cassert&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &lt;map&gt;

using namespace std;

#define forn(i, n) for (int i = 0; i &lt; (int)(n); i++)

typedef unsigned long long ll;

int w, h, is[32][32];

map &lt;ll, ll&gt; f;

ll go( int x, int y )
{
  if (++x == w)
    y++, x = 0;
  if (y == h)
    return 1;

  ll hash = (x &lt;&lt; 5) + y;
  forn(dy, 2)
    forn(t, w)
    {
      int y1 = y + dy + (t &lt; x);
      hash = hash * 2 + (y1 &lt; h ? is[y1][t] : 0);
    }
  if (f.count(hash))
    return f[hash];
  ll &r = f[hash];
  r = 0;
  if (is[y][x])
    r += go(x, y);
  else
  {
    if (x + 2 &lt; w && !is[y][x + 1] && !is[y][x + 2])
    {
      is[y][x + 1] = is[y][x + 2] = 1;
      r += go(x, y);
      is[y][x + 1] = is[y][x + 2] = 0;
    }
    if (y + 2 &lt; h && !is[y + 1][x])
    {
      is[y + 1][x] = is[y + 2][x] = 1;
      r += go(x, y);
      is[y + 1][x] = is[y + 2][x] = 0;
    }
  }
  return r;
}

int main()
{
  #define NAME "dominoes"
  assert(freopen(NAME ".in", "r", stdin));
  assert(freopen(NAME ".out", "w", stdout));

  cin &gt;&gt; w &gt;&gt; h;
  cout &lt;&lt; go(-1, 0) &lt;&lt; endl;
  return 0;
}

</code></pre>

</body>
</html>

<font style="visibility:hidden">
